package com.oracle.application.listener;

import com.oracle.application.service.SendEmailService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author bug制造者
 * @ClassName SendEmailListener.java
 * @createTime 2021年07月09日 09:18:00
 * @Description
 */
@Component
public class SendEmailListener {

    @Autowired
    private SendEmailService sendEmailService;

    @RabbitListener(queues = "emailQueue")
    @RabbitHandler
    public void getMessage(Channel channel, Message message){
        String targetEmail = new String(message.getBody());
        System.out.println("邮箱是："+targetEmail);
        System.out.println("-----------------"+sendEmailService);
        sendEmailService.sendEmailCode(targetEmail);
    }
}
